package com.baidu.ota.utils;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;

import com.baidu.otasdk.ota.Constants;

public final class MetaData {
    private static Bundle metaData;

    public static final String UI_INTERACT = "UI_INTERACT";                     // 是否有ui交互 boolean
    public static final String PRESET_APPS = "PRESET_APPS";                     // 预置app包名列表
    public static final String PRODUCT_ID = "PRODUCT_ID";                       // 产品线ID
    public static final String PRODUCT_KEY = "PRODUCT_KEY";                     // 产品线KEY
    public static final String OPTION = "OPTION";                               // 下载配置
    public static final String EXTRA = "EXTRA";                                 // 其他配置
    public static final String NOTIFY_PACKAGE = "NOTIFY_PACKAGE";               // 广播通知的包名

    public static final String OTA_VERSION_FIELD = "OTA_VERSION_FIELD";
    public static final String DEVICE_ID_FIELD = "DEVICE_ID_FIELD";
    public static final String CHANNEL_FIELD = "CHANNEL_FIELD";
    public static final String PRODUCT_ID_FIELD = "PRODUCT_ID_FIELD";
    public static final String PRODUCT_KEY_FIELD = "PRODUCT_KEY_FIELD";

    public static void init(Context context) {
        try {
            String pkg = context.getPackageName();
            metaData = context.getPackageManager().getApplicationInfo(pkg, PackageManager.GET_META_DATA).metaData;
        } catch (Exception e) {
            Log.e(Constants.TAG, e.toString());
        }
    }

    public static String getString(String key) {
        return metaData.getString(key, "");
    }

    public static int getInt(String key) {
        return metaData.getInt(key, 0);
    }

    public static boolean getBool(String key) {
        return metaData.getBoolean(key);
    }
}
